<template>
</template>
<script>
	export default {
		data() {
			return {
				cityName: "Guangzhou",
				cityId: 1, //北京:1  上海:3  深圳:2
				stateSum: 0,
				stateX: 0,
				isOne: false,
				isTrue: true,
				isShow: false,
				widthItem: 0,
				city: [],
				citys: [],
				posterSrc: ""

				// posterSrc: require("../static/videoImg.png")
			}
		},
		methods: {
			toJSON(){
				return this
			},
			inIt() {
				uni.setStorageSync('cityId',this.cityId);
				this.cityInit().then(res => {
					this.city.forEach(item => {
						// console.log('===>', item.id == this.cityId, item.id, this.cityId)
						if (item.id == this.cityId) {
							console.log("当前的城市id------>",this.cityId)
							this.ff_click(item.id, item.bgimage);
						}
					});
				});
			},
			cityInit() {
				return new Promise((ress, rejj) => {
					this.$api.apiCities().then(res => {
						if (res.code == 200) {
							// console.log("res===>", res.data);
							this.city = res.data;
							ress();
						}
					});
				});
			},
			ff_click(id, bgimage) {
				let src = `api/cities/${id}/display`;
				this.$api.apiDiplay(src).then(res => {
					if (res.code == 200) {

						// console.log("res====>", res.data);
						let newData = JSON.parse(JSON.stringify(res.data));
						newData.forEach(item => {
							item.background = bgimage;
						});
						// 
						let Ndata = this.$Tools.ff_package(newData);
						Ndata = [Ndata,Ndata];

						let Ndata_end_nunber = Ndata.length - 1;

						uni.setStorageSync('bgimage', bgimage);
						// console.log('bgimage===>', bgimage)

						uni.setStorage({
							key: 'brandArrs',
							data: JSON.stringify(Ndata),
							success: function() {
								// console.log('异步了!!');
								uni.navigateTo({
									url: '../container/container'
								});
							}
						});
					}
				});
			},
			},
		onLoad: function() {
			let that = this;
			uni.getNetworkType({
				success: (res) => {

					let isConnected = res.networkType == "none" ? false : true;
					uni.setStorageSync('isConnected', isConnected);
					// console.log("是否离线 true为有网 false为无网==================>", isConnected);
					if (isConnected) {
						
					
						// 直奔指定城市
						that.inIt();
						uni.setStorageSync('isdDownload', false);
					} else {
						uni.getStorage({
							key: 'brandArrs',
							success: (ress) => {
								console.log('获取本地离线数据异步了!! <===========================', ress);
								uni.navigateTo({
									url: '../container/container'
								});
								uni.setStorageSync('isdDownload', true);
							},
							fail: () => {
								uni.showToast({
									icon: 'error',
									title: '第一次请联网',
									duration: 50000
								})
							}
						});
					}

				}
			});
		},

	}
</script>

<style>
	html,
	body {
		width: 100%;
		height: 100vh;

	}

	.FULLsss {
		width: 100%;
		height: 100vh;
		background-size: 100%;
	}

	#app {
		width: 100%;
		height: 100vh;
	}

	/*每个页面公共css */
</style>
